/**
 * 版权所有@2015 北京博创联动科技有限公司；未经许可，不得擅自复制、传播；
 */
package com.uptech.homer.beans.body;

import com.uptech.homer.beans.AlarmInfo;
import com.uptech.homer.beans.CanBodyAdapter;
import com.uptech.homer.beans.Message;
import com.uptech.homer.beans.annotation.AlarmField;
import com.uptech.homer.beans.annotation.CANField;
import com.uptech.homer.itf.IAccumulatedMileage;
import com.uptech.homer.itf.IBatteryAlarm;
import com.uptech.homer.itf.IBatteryPackData;
import com.uptech.homer.itf.IDriveMotorData;
import com.uptech.homer.itf.IGpsData;
import com.uptech.homer.itf.IIgnitionOffTime;
import com.uptech.homer.itf.IVehicleStatus;
import com.uptech.homer.util.ByteUtils;

import java.text.DecimalFormat;

/**
 * 小康车身CAN消息体
 *
 * @author lei
 */
public class RptXKCan extends CanBodyAdapter implements IIgnitionOffTime, IAccumulatedMileage, IGpsData, IDriveMotorData, IVehicleStatus, IBatteryPackData, IBatteryAlarm {
    public static final int _typeCode = 0x0010;
    private static final long serialVersionUID = 1L;
    private static final DecimalFormat decimalFormatter = new DecimalFormat("0.000");
    private static final DecimalFormat decimalFormatters = new DecimalFormat("0.00");
    private static final DecimalFormat decimalFormatterss = new DecimalFormat("0.0");

    /*****0x1810DBEF*******/

    /**
     * 电机转速
     *
     * @return
     */
    @CANField(group = "电机控制器", name = "电机转速", suffix = "rpm")
    public int getMotorRpm() {
        return ByteUtils.getInt(data, 12, 14);
    }

    /**
     * 控制器温度
     *
     * @return
     */
    @CANField(group = "电机控制器", name = "控制器温度", suffix = "°C")
    public int getControlTemp() {
        return ByteUtils.getInt(data, 14, 16);
    }

    /**
     * 电机温度
     *
     * @return
     */
    @CANField(group = "电机控制器", name = "电机温度", suffix = "°C")
    public double getMotorTemp() {
        return ByteUtils.getInt(data, 16, 18);
    }

    public byte getDriveStatus() {
        return (byte) (ByteUtils.getRange(data, 18, 19)[0] & 0x0F);
    }

    public byte getDriveMode() {
        return (byte) ((ByteUtils.getRange(data, 18, 19)[0] & 0x30) >> 4);
    }

    public byte getChargLock() {
        return (byte) ((ByteUtils.getRange(data, 18, 19)[0] & 0x40) >> 6);
    }

    public byte getBreakStatus() {
        return (byte) (ByteUtils.getRange(data, 19, 20)[0] & 0x01);
    }

    /*****0x1811DBEF********/

    /**
     * 电池电压
     *
     * @return
     */
    @CANField(group = "电机控制器", name = "电池电压", suffix = "V")
    public String getBatteryVol() {
        return decimalFormatter.format(ByteUtils.getInt(data, 20, 22) * 0.1);
    }

    /**
     * 加速器输入
     *
     * @return
     */
    @CANField(group = "电机控制器", name = "加速器输入", suffix = "%")
    public String getThrottle() {

        double value = ByteUtils.getUnsignedShort(data, 23, 25);

        if (value > 500) {

            return "" + ((int) (Double.parseDouble(decimalFormatters.format(Math.abs(value - 1000) / 80)) * 100));

        } else if ((value >= 100) && (value <= 500)) {

            return "100";

        } else if ((value >= 0) && (value <= 99)) {
            return "" + value;
        }

        return "" + value;

    }

	/*@CANField(group = "电机控制器", name = "加速器输入扭矩", suffix = "N.M")
    public int get_Throttle() {
		
		int value = ByteUtils.getUnsignedShort(data, 23, 25);
		
		if (value > 500) {
			return value - 1000;
		}
		
		return 0;
		
	}*/

    public byte getMotorStatus() {
        return (byte) ((ByteUtils.getRange(data, 26, 27)[0] & 0xC0) >> 6);
    }

    public byte getContactorStatus() {
        return (byte) ((ByteUtils.getRange(data, 27, 28)[0] & 0xC0) >> 6);
    }

    /*****0x1812EFDB******/

    /**
     * 速度
     *
     * @return
     */
    @CANField(group = "仪表", name = "速度", suffix = "KM/H")
    public String get_Speed() {
        return decimalFormatter.format(ByteUtils.getInt(data, 28, 30) / 10D);
    }

    /**
     * 里程
     *
     * @return
     */
    @CANField(group = "仪表", name = "里程", suffix = "KM")
    public String getTotal_Mileage() {
        System.out.println("##################");
        System.out.println(data);
        return decimalFormatter.format(ByteUtils.getUnsignedInt(data, 30, 34) * 0.1);
    }

    /******0x1808EFF4*******/

    /**
     * 剩余电量SOC
     *
     * @return
     */
    /*@CANField(group = "电池管理系统", name = "剩余电量SOC", suffix = "%")
	public double get_SOC() {
		return ByteUtils.getUnsignedInt(data, 36, 37);
	}*/

    /**
     * 电池组最高温度
     *
     * @return
     */
    @CANField(group = "电池管理系统", name = "电池组最高温度", suffix = "℃")
    public double getBatGroupMaxTemp() {
        return ByteUtils.getUnsignedInt(data, 37, 38);
    }

    /**
     * 电池组最低温度
     *
     * @return
     */
    @CANField(group = "电池管理系统", name = "电池组最低温度", suffix = "℃")
    public double getBatGroupMinTemp() {
        return ByteUtils.getUnsignedInt(data, 38, 39);
    }

    /**
     * 电池组总电压
     *
     * @return
     */
    @CANField(group = "电池管理系统", name = "电池组总电压", suffix = "V")
    public String getBatGroupTotalVol() {
        return decimalFormatterss.format(ByteUtils.getUnsignedInt(data, 42, 44) * 0.1);
    }

    /******0x18EF08EF*******/

    /******0x18EF0803*******/

    /**
     * 充电次数
     *
     * @return
     */
    @CANField(group = "电池管理系统", name = "充电次数", suffix = "次")
    public int getChargeTime() {
        return ByteUtils.getUnsignedShort(data, 56, 58);
    }

    /**
     * 电池健康指数SOH%
     *
     * @return
     */
    @CANField(group = "电池管理系统", name = "电池健康指数SOH", suffix = "%")
    public int getBatSOH() {
        int n = ByteUtils.getUnsignedShort(data, 58, 59);

        if (n > 100) {

            n = 100;
        }
        return n;
    }

    /******0x18EF08E5*******/

    /******0x1802DBF4******/

    /**
     * 充电状态
     *
     * @return
     */
    @CANField(group = "电池管理系统", name = "充电状态")
    public String getChargStatus() {

        switch (ByteUtils.getUnsignedShort(data, 68, 69)) {

            case 0x00:
                return "无充电机连接";
            case 0x01:
                return "充电机已准备";
            case 0x02:
                return "正在充电";
            case 0x03:
                return "充电完成";
            default:
                return "";
        }
    }

    /**
     * 电池单体最高温度
     *
     * @return
     */
    @CANField(group = "电池管理系统", name = "电池单体最高温度", suffix = "℃")
    public String getSingleBatMaxTemp() {
        return decimalFormatter.format(ByteUtils.getShort(data, 69, 70));
    }

    /**
     * 剩余电量
     *
     * @return
     */
    @CANField(group = "电池管理系统", name = "剩余电量", suffix = "%")
    public double getSOC() {
        return ByteUtils.getUnsignedShort(data, 70, 71);
    }

    /**
     * 电池组状态
     *
     * @return
     */
	/*@CANField(group = "电池管理系统", name = "电池组状态")
	public String getBatStatus() {
		String str = "";

		short b = ByteUtils.getShort(data, 71, 72);

		str += (((b & 0x01) == 0) ? "" : "单体电压过大  ") + (((b & 0x02) >> 1 == 0) ? "正常" : "单体电压过小  ")
				+ (((b & 0x04) >> 2 == 0) ? "" : "峰值放电电流过大  ") + (((b & 0x08) >> 3 == 0) ? "正常" : "温度过高  ")
				+ (((b & 0x10) >> 4 == 0) ? "" : "节点错误  ") + (((b & 0x20) >> 5 == 0) ? "正常" : "蓄电池切断功能  ")
				+ (((b & 0x40) >> 6 == 0) ? "" : "蓄电池故障功能  ") + (((b & 0x80) >> 7 == 0) ? "正常" : "绝缘状态");

		return str;
	}*/

    /**
     * 单体电压过大
     *
     * @return
     */
    @CANField(group = "电池管理系统", name = "单体电压过大")
    public String getCellVolOver() {
        return ((ByteUtils.getShort(data, 71, 72) & 0x01) == 0) ? "正常" : "单体电压过大 ";
    }

    /**
     * 单体电压过小
     *
     * @return
     */
    @CANField(group = "电池管理系统", name = "单体电压过小")
    public String getCellVolLess() {
        return (((ByteUtils.getShort(data, 71, 72) & 0x02) >> 1) == 0) ? "正常" : "单体电压过小  ";
    }

    /**
     * 峰值放电电流过大
     *
     * @return
     */
    @CANField(group = "电池管理系统", name = "峰值放电电流过大")
    public String getPeakDischargeCurrentTooLarge() {
        return (((ByteUtils.getShort(data, 71, 72) & 0x04) >> 2) == 0) ? "正常" : "峰值放电电流过大 ";
    }

    /**
     * 温度过高
     *
     * @return
     */
    @CANField(group = "电池管理系统", name = "温度过高")
    public String getTempOver() {
        return (((ByteUtils.getShort(data, 71, 72) & 0x08) >> 3) == 0) ? "正常" : "峰值放电电流过大 ";
    }

    /**
     * 节点错误
     *
     * @return
     */
    @CANField(group = "电池管理系统", name = "节点错误")
    public String getNodeError() {
        return (((ByteUtils.getShort(data, 71, 72) & 0x10) >> 4) == 0) ? "正常" : "节点错误";
    }

    /**
     * 蓄电池切断功能
     *
     * @return
     */
    @CANField(group = "电池管理系统", name = "蓄电池切断功能")
    public String getBatteryCutOffFunction() {
        return (((ByteUtils.getShort(data, 71, 72) & 0x20) >> 5) == 0) ? "正常" : "蓄电池切断功能";
    }

    /**
     * 蓄电池故障功能
     *
     * @return
     */
    @CANField(group = "电池管理系统", name = "蓄电池故障功能 ")
    public String getBatteryFaultFunction() {
        return (((ByteUtils.getShort(data, 71, 72) & 0x40) >> 6) == 0) ? "正常" : "蓄电池切断功能";
    }

    /**
     * 绝缘状态
     *
     * @return
     */
    @CANField(group = "电池管理系统", name = "绝缘状态 ")
    public String getInsulationState() {
        return (((ByteUtils.getShort(data, 71, 72) & 0x80) >> 7) == 0) ? "正常" : "绝缘状态";
    }

    /**
     * 母线电流
     *
     * @return
     */
    @CANField(group = "电池管理系统", name = "母线电流", suffix = "A")
    public String get_Electric() {
        return decimalFormatters.format(ByteUtils.getInt(data, 72, 74) / 10D);
    }

    /**
     * 母线电压
     *
     * @return
     */
    @CANField(group = "电池管理系统", name = "母线电压", suffix = "V")
    public String get_Voltage() {
        return decimalFormatter.format(ByteUtils.getInt(data, 74, 76) / 10D);
    }

    /*******0x1803DBF4******/

    // AS3

    /**
     * 电池单体最高电压
     *
     * @return
     */
    @CANField(group = "电池管理系统", name = "电池单体最高电压", suffix = "V")
    public String getSingleBatMaxVol() {
        return decimalFormatter.format(ByteUtils.getInt(data, 76, 78) / 1000D);
    }

    /**
     * 电池单体最低电压
     *
     * @return
     */
    @CANField(group = "电池管理系统", name = "电池单体最低电压", suffix = "V")
    public String getSingleBatMinVol() {
        return decimalFormatter.format(ByteUtils.getInt(data, 78, 80) / 1000D);
    }

    public String getChargStatus2() {

        short b = ByteUtils.getShort(data, 80, 81);

        String str = "";

        switch (b & 0x03) {
            case 0:
                str += "非充电状态  ";
                break;
            case 1:
                str += "电量低于20%  ";
                break;
            case 2:
                str += "电量20%-80%  ";
                break;
            case 3:
                str += "电量大于80%  ";
                break;
        }

        switch ((b & 0x30) >> 2) {
            case 0:
                str += "非充电状态  ";
                break;
            case 1:
                str += "充电桩32P  ";
                break;
            case 2:
                str += "电量20%-80%  ";
                break;
            case 3:
                str += "电量大于80%  ";
                break;
        }

        return str;
    }

    /**
     * 绝缘电阻
     *
     * @return
     */
    @CANField(group = "电池管理系统", name = "绝缘电阻", suffix = "KΩ")
    public int getInsRessistance() {
        return ByteUtils.getUnsignedShort(data, 81, 83);
    }

    /**
     * 过放电次数
     *
     * @return
     */
    //	@CANField(group = "电池管理系统", name = "过放电次数", suffix = "次")
    //	public int getOverdischargeTime() {
    //		return ByteUtils.getUnsignedShort(data, 83, 84);
    //	}

    /*****0x18FA50D1********/

    // MD

    /**
     * 控制器故障代码
     *
     * @return
     */
    @CANField(group = "电池管理系统", name = "控制器故障代码")
    public String getControllerFaultCode() {
        String str = "";
        short b = ByteUtils.getShort(data, 46, 47);
        switch (b) {
            case 1:
                str += "母线电流过流  ";
                break;
            case 2:
                str += "模块故障  ";
                break;
            case 3:
                str += "相电流过流  ";
                break;
            case 4:
                str += "母线电压过压  ";
                break;
            case 5:
                str += "电机超速  ";
                break;
            case 6:
                str += "电机温度过热  ";
                break;
            case 7:
                str += "控制器温度过热  ";
                break;
            case 8:
                str += "母线电压欠压  ";
                break;
            case 9:
                str += "相电流过载  ";
                break;
            case 10:
                str += "油门踏板状态  ";
                break;
            case 11:
                str += "控制器温度报警  ";
                break;
            case 12:
                str += "电机温度报警  ";
                break;
            case 13:
                str += "堵转保护  ";
                break;
            case 14:
                str += "SOC低于20%报警  ";
                break;
            case 15:
                str += "12V欠压  ";
                break;
            case 16:
                str += "CAN通信故障  ";
                break;
            case 17:
                str += "预充电失败  ";
                break;
            case 18:
                str += "加速器双校验失败  ";
                break;
            case 19:
                str += "旋变线故障  ";
                break;
            default:
                str += "无  ";
                break;
        }
        return str;
    }

    // BGD

    /**
     * BMS自身故障代码
     *
     * @return
     */
    @AlarmField(group = "电池管理系统")
    public AlarmInfo getBMSFaultCode() {
        int level = ByteUtils.getShort(data, 52, 53) & 0x1C;

        String str = "";
        String code = null;
        switch (level) {
            case 0:
                str += "BMS正常  ";
                break;
            case 1:
                str += "1级（一般故障） ";
                break;
            case 2:
                str += "2级（次高级故障） ";
                break;
            case 3:
                str += "3级（最高级故障） ";
                break;
            default:
                str += "数据异常";
                level = -1;
                break;
        }
        return new AlarmInfo("BMS自身故障代码", str, level, code);
    }

    /**
     * 充电机硬件故障
     *
     * @return
     */
    @AlarmField(group = "电池管理系统")
    public AlarmInfo getHardWareFalut() {
        int level = ByteUtils.getShort(data, 54, 55) & 0x01;

        String str = "";
        String code = null;
        if (level == 0) {

            str += "充电机正常";
        } else {

            str += "充电机硬件故障";
        }
        return new AlarmInfo("充电机硬件故障", str, level, code);
    }

    /**
     * 充电机温度过高保护
     *
     * @return
     */
    @AlarmField(group = "电池管理系统")
    public AlarmInfo getMTempFalut() {
        int level = (ByteUtils.getShort(data, 54, 55) & 0x02) >> 1;

        String str = "";
        String code = null;
        if (level == 0) {

            str += "充电机温度正常";
        } else {

            str += "充电机温度过高保护";
        }
        return new AlarmInfo("充电机温度过高保护", str, level, code);
    }

    /**
     * 充电紧急输入电压
     *
     * @return
     */
    @AlarmField(group = "电池管理系统")
    public AlarmInfo getMFVolFalut() {
        int level = (ByteUtils.getShort(data, 54, 55) & 0x04) >> 2;

        String str = "";
        String code = null;
        if (level == 0) {

            str += "充电紧急输入电压正常";
        } else {

            str += "充电机输入电压错误，充电机停止工作";
        }
        return new AlarmInfo("充电紧急输入电压", str, level, code);
    }

    /**
     * 充电器检测到电池电压状态
     *
     * @return
     */
    @AlarmField(group = "电池管理系统")
    public AlarmInfo getBVolFalut() {
        int level = (ByteUtils.getShort(data, 54, 55) & 0x08) >> 3;

        String str = "";
        String code = null;
        if (level == 0) {

            str += "充电器检测到电池电压进入启动状态";
        } else {

            str += "充电机处于关闭状态(防止电池反接)";
        }
        return new AlarmInfo("充电机温度故障", str, level, code);
    }

    /**
     * 充电机通信
     *
     * @return
     */
    @AlarmField(group = "电池管理系统")
    public AlarmInfo getMContactFalut() {
        int level = (ByteUtils.getShort(data, 54, 55) & 0x10) >> 4;

        String str = "";
        String code = null;
        if (level == 0) {

            str += "充电机通信正常";
        } else {

            str += "充电机通信接收超时";
        }
        return new AlarmInfo("充电机通信", str, level, code);
    }

    /**
     * 电池组系统故障代码
     *
     * @return
     */
    @AlarmField(group = "电池管理系统")
    public AlarmInfo getBatSysFaultCodes() {
        int level = ByteUtils.getShort(data, 55, 56);

        String str = "";
        String code = null;
        switch (level) {
            case 1:
                str += "一级故障 电池温度过高 ";
                level = 1;
                break;
            case 3:
                str += "一级故障 单体充电电压过高";
                level = 1;
                break;
            case 5:
                str += "一级故障 总电压过高";
                level = 1;
                break;
            case 6:
                str += "一级故障 总电压过低";
                level = 1;
                break;
            case 7:
                str += "一级故障 快充电流过大";
                level = 1;
                break;
            case 8:
                str += "一级故障 放电电流过大";
                level = 1;
                break;
            case 9:
                str += "一级故障 电池温差过大";
                level = 1;
                break;
            case 10:
                str += "一级故障 接触器故障";
                level = 1;
                break;
            case 11:
                str += "一级故障 电池充电温度过低";
                level = 1;
                break;
            case 12:
                str += "一级故障 电池放电温度过低";
                level = 1;
                break;
            case 13:
                str += "一级故障 单体充电电压过低";
                level = 1;
                break;
            case 14:
                str += "一级故障 单体放电电压过低";
                level = 1;
                break;
            case 52:
                str += "一级故障 绝缘故障";
                level = 1;
                break;
            case 16:
                str += "一级故障 自检故障";
                level = 1;
                break;
            case 17:
                str += "一级故障 预充失败";
                level = 1;
                break;
            case 18:
                str += "一级故障 加热失效";
                level = 1;
                break;
            case 19:
                str += "一级故障 极柱温度过高";
                level = 1;
                break;
            case 51:
                str += "电池温度过高";
                level = 2;
                break;
            case 102:
                str += "绝缘故障";
                level = 2;
                break;
            case 53:
                str += "电池温度过低";
                level = 2;
                break;
            case 54:
                str += "单体充电电压过高";
                level = 2;
                break;
            case 55:
                str += "单体电压过低";
                level = 2;
                break;
            case 56:
                str += "总电压过高";
                level = 2;
                break;
            case 57:
                str += "总电压过低";
                level = 2;
                break;
            case 58:
                str += "充电电流过大";
                level = 2;
                break;
            case 59:
                str += "放电电流过大";
                level = 2;
                break;
		/*case 60:
			str += "SOC过低";
			level = 1;
			break;*/
            case 61:
                str += "电池温差过大";
                level = 2;
                break;
            case 62:
                str += "电池充电温度过低";
                level = 2;
                break;
            case 63:
                str += "电池放电温度过低";
                level = 2;
                break;
            case 64:
                str += "单体充电电压过低";
                level = 2;
                break;
            case 65:
                str += "单体放电电压过低";
                level = 2;
                break;
            case 66:
                str += "单体动态压差";
                level = 2;
                break;
            case 67:
                str += "加热失效";
                level = 2;
                break;
            case 68:
                str += "极柱温度过高";
                level = 2;
                break;
            case 69:
                str += "内部通讯故障";
                level = 2;
                break;
            case 70:
                str += "线束故障";
                level = 2;
                break;
            case 71:
                str += "12V欠压故障";
                level = 2;
                break;
            case 101:
                str += "电池最高温度过高";
                level = 2;
                break;
            case 103:
                str += "单体放电电压过高";
                level = 2;
                break;
            case 104:
                str += "电池最低温度过低";
                level = 2;
                break;
            case 105:
                str += "单体电压过高";
                level = 2;
                break;
            case 106:
                str += "单体电压过低";
                level = 2;
                break;
            case 107:
                str += "总电压过高";
                level = 2;
                break;
            case 108:
                str += "总电压过低";
                level = 2;
                break;
            case 109:
                str += "充电电流过大";
                level = 2;
                break;
            case 110:
                str += "放电电流过大";
                level = 2;
                break;
            case 111:
                str += "温差过大";
                level = 2;
                break;
		/*case 112:
			str += "SOC过低";
			level = 1;
			break;*/
            case (byte) 151:
                str += "绝缘故障";
                level = 2;
                break;
            case (byte) 152:
                str += "单体最低电压过低";
                level = 2;
                break;
            default:
                str += "正常";
                level = -1;
                break;
        }
        return new AlarmInfo("电池组系统故障", str, level, code);
    }


    /**
     * BMS接触器status
     *
     * @return
     */
    @CANField(group = "电池管理系统", name = "BMS接触器状态")
    public String getBMSContactorStatus() {
        String str = "";
        short b = ByteUtils.getShort(data, 59, 60);
        switch (b & 0x03) {
            case 0:
                str += "充电控制接触器吸合 ";
                break;
            case 1:
                str += "充电控制接触器断开 ";
                break;
            case 2:
                str += "充电控制接触器线圈开路/短路 ";
                break;
            case 3:
                str += "充电控制接触器触点粘连 ";
                break;
        }
        switch ((b & 0x0C) >> 2) {
            case 0:
                str += "预充电继电器吸合 ";
                break;
            case 1:
                str += "预充电继电器断开 ";
                break;
            case 2:
                str += "预充电继电器线圈开路/短路 ";
                break;
            case 3:
                str += "预充电继电器触点粘连 ";
                break;
        }
        switch ((b & 0x30) >> 4) {
            case 0:
                str += "电池负极电池主接触器吸合 ";
                break;
            case 1:
                str += "电池负极极主接触器断开 ";
                break;
            case 2:
                str += "电池负极接触器线圈开路/短路 ";
                break;
            case 3:
                str += "电池负极接触器触点粘连 ";
                break;
        }
        switch ((b & 0xC0) >> 6) {
            case 0:
                str += "电池正极电池主接触器吸合 ";
                break;
            case 1:
                str += "电池正极主接触器断开 ";
                break;
            case 2:
                str += "电池正极接触器线圈开路/短路 ";
                break;
            case 3:
                str += "电池正极接触器触点粘连 ";
                break;
        }
        return str;
    }

    @Override
    public double getSpeed() {
        return Double.parseDouble(get_Speed());
    }

    @Override
    public double getTotalMileage() {
        return Double.parseDouble(getTotal_Mileage());
    }

    @Override
    public double getElectric() {
        return Double.parseDouble(get_Electric());
    }

    @Override
    public double getVoltage() {
        return Double.parseDouble(get_Voltage());
    }

    @Override
    public int getACCState() {
        return -1;
    }

    public byte[] getIgnitionTime() {
        // TODO Auto-generated method stub
        return new byte[]{00, 00, 00, 00, 00, 00};
    }

    public byte[] getOffTime() {
        // TODO Auto-generated method stub
        return new byte[]{00, 00, 00, 00, 00, 00};
    }

    @Override
    public byte[] getAccumulateMileage() {
        return ByteUtils.getRangeConvert(data, 30, 34);
    }

    @Override
    public byte[] getRange() {
        // TODO Auto-generated method stub
        return new byte[]{};
    }

    @Override
    public byte[] getMotorControllerTemperature() {
        int ds = ByteUtils.getInt(data, 14, 16) + 40;
        return new byte[]{(byte) ds};
    }

    @Override
    public byte[] getMotorSpeed() {
        return ByteUtils.shortToByte((short) (ByteUtils.getInt(data, 12, 14)));
    }

    @Override
    public byte[] getMotorTemperature() {
        int ds = ByteUtils.getInt(data, 16, 18) + 40;
        return new byte[]{(byte) ds};
    }

    @Override
    public byte[] getMotorBusbarCurrent() {
        return ByteUtils.shortToByte((short) (((ByteUtils.getInt(data, 72, 74) / 10) + 1000) * 10));
    }

    @Override
    public byte[] getMotorControllerBeforeVoltage() {
        return ByteUtils.shortToByte((short) ByteUtils.getUnsignedInt(data, 42, 44));
    }

    @Override
    public byte[] getMotorControllerAfterVoltage() {
        // TODO Auto-generated method stub
        return new byte[]{};
    }

    @Override
    public byte[] getMotorController() {
        // TODO Auto-generated method stub
        return new byte[]{};
    }

    @Override
    public byte[] getMotorTorque() {
        // TODO Auto-generated method stub
        return new byte[]{};
    }

    @Override
    public byte[] getAcceleratorPedalStroke() {
        return ByteUtils.getBytes(new Double(getThrottle()).intValue(), new byte[1]);
    }

    @Override
    public byte[] getBrakePedalStroke() {
        // TODO Auto-generated method stub
        return new byte[]{00};
    }

    @Override
    public byte[] getPowerSystemPlace() {
        // TODO Auto-generated method stub
        return new byte[]{00};
    }

    @Override
    public byte[] getEmergencyPowerRequest() {
        // TODO Auto-generated method stub
        return new byte[]{00};
    }

    @Override
    public byte[] getCurrentVehicleState() {

        byte[] ret = new byte[1];

        if ("正在充电".equals(getChargStatus())) {
            ret[0] = 0x02;
        } else {
            if (ByteUtils.getInt(data, 28, 30) > 0) {
                ret[0] = 0x01;
            } else {
                ret[0] = 0x00;
            }
        }

        return ret;
    }

    @Override
    public byte[] getHighVoltageBatteryCurrent() {
        // TODO Auto-generated method stub
        return new byte[]{00, 00};
    }

    @Override
    public byte[] getSoc() {
        return new byte[]{(byte) (ByteUtils.getInt(data, 70, 71) / 0.4)};
    }

    @Override
    public byte[] getRemainEnergy() {
        double soc = ByteUtils.getUnsignedShort(data, 70, 71);
        Double reEnergy = new Double(soc) * 25.92 * 10;
        return ByteUtils.getBytes(reEnergy.intValue(), new byte[2]);
    }

    @Override
    public byte[] getBatteryVoltageAlways() {
        Double vol = new Double(get_Voltage()) * 10;
        return ByteUtils.getBytes(vol.intValue(), new byte[2]);
    }

    @Override
    public byte[] getBatteryPackMaxTemperatureInPackageSerialNumber() {
        // TODO Auto-generated method stub
        return new byte[]{};
    }

    @Override
    public byte[] getBatteryPackMaxTemperatureData() {
        // TODO Auto-generated method stub
        return new byte[]{};
    }

    @Override
    public byte[] getBatteryPackMinTemperatureInPackageSerialNumber() {
        // TODO Auto-generated method stub
        return new byte[]{};
    }

    @Override
    public byte[] getBatteryPackMinTemperatureData() {
        // TODO Auto-generated method stub
        return new byte[]{};
    }

    @Override
    public byte[] getBatteryPackMaxVoltageInPackageSerialNumber() {
        // TODO Auto-generated method stub
        return new byte[]{};
    }

    @Override
    public byte[] getBatteryPackMaxVoltageData() {
        // TODO Auto-generated method stub
        return new byte[]{};
    }

    @Override
    public byte[] getBatteryPackMinVoltageInPackageSerialNumber() {
        // TODO Auto-generated method stub
        return new byte[]{};
    }

    @Override
    public byte[] getBatteryPackMinVoltageData() {
        // TODO Auto-generated method stub
        return new byte[]{};
    }

    @Override
    public byte[] getSigBatteryPackMaxTemperatureInPackageSerialNumber() {
        // TODO Auto-generated method stub
        return new byte[]{};
    }

    @Override
    public byte[] getSigMaxTemperatureNumber() {
        // TODO Auto-generated method stub
        return new byte[]{};
    }

    @Override
    public byte[] getSigMaxTemperature() {
        // TODO Auto-generated method stub
        return new byte[]{(byte) (ByteUtils.getInt(data, 69, 70) + 40)};
    }

    @Override
    public byte[] getSigBatteryPackMinTemperatureInPackageSerialNumber() {
        // TODO Auto-generated method stub
        return new byte[]{};
    }

    @Override
    public byte[] getSigMinTemperatureNumber() {
        // TODO Auto-generated method stub
        return new byte[]{};
    }

    @Override
    public byte[] getSigMinTemperature() {
        // TODO Auto-generated method stub
        return new byte[]{00};
    }

    @Override
    public byte[] getSigBatteryPackMaxVoltageInPackageSerialNumber() {
        // TODO Auto-generated method stub
        return new byte[]{};
    }

    @Override
    public byte[] getSigMaxVoltageNumber() {
        // TODO Auto-generated method stub
        return new byte[]{};
    }

    @Override
    public byte[] getSigMaxVoltage() {
        // TODO Auto-generated method stub
        return ByteUtils.getRangeConvert(data, 76, 78);
    }

    @Override
    public byte[] getSigBatteryPackMinVoltageInPackageSerialNumber() {
        // TODO Auto-generated method stub
        return new byte[]{};
    }

    @Override
    public byte[] getSigMinVoltageNumber() {
        // TODO Auto-generated method stub
        return new byte[]{};
    }

    @Override
    public byte[] getSigMinVoltage() {
        // TODO Auto-generated method stub
        return ByteUtils.getRangeConvert(data, 78, 80);
    }

    @Override
    public byte[] getInsulationResistanceValue() {
        // TODO Auto-generated method stub
        return ByteUtils.getRangeConvert(data, 81, 83);
    }

    @Override
    public byte[] getBatteryEqualizationActivation() {
        if (getChargeTime() > 0) {
            return new byte[]{01};
        } else {
            return new byte[]{00};
        }
    }

    @Override
    public byte[] getLiquidFuelConsumption() {
        // TODO Auto-generated method stub
        return new byte[]{00, 00};
    }

    @Override
    public byte[] getMaxDischargeBatteryPack() {
        // TODO Auto-generated method stub
        return new byte[]{};
    }

    @Override
    public byte[] getMaxChargingeBatteryPack() {
        // TODO Auto-generated method stub
        return new byte[]{};
    }

    @Override
    public byte[] getGpsData(Message message) {
        RptGpsInfo gpsInfo = message.findBody(RptGpsInfo.class);

        byte[] msgCode = ByteUtils.getBytes(0x03, new byte[1]);
        // 定位状态
        byte[] gpsStatus = new byte[]{0}/*ByteUtils.getBytes(((gpsInfo.getGpsStatusVal() >> 1 & 0x01) == 1 ? 0 : 1), new byte[1])*/;

        // 经度
        byte[] lon = ByteUtils.getRangeConvert(gpsInfo.getGpsLon());
        // 纬度
        byte[] lat = ByteUtils.getRangeConvert(gpsInfo.getGpsLat());
        // 速度
        byte[] speed = ByteUtils.shortToByte((short) (ByteUtils.getInt(data, 28, 30)));  /* ByteUtils.shortToByte((short) gpsInfo.getGpsSpeedVal())*/
        ;
        // 方向
        byte[] direction = ByteUtils.getRangeConvert(gpsInfo.getGpsDirection());

        // 预留
        byte[] obt = ByteUtils.getBytes(0, new byte[4]);
        byte[] gps = new byte[msgCode.length + gpsStatus.length + lon.length + lat.length + speed.length + direction.length + obt.length];
        ByteUtils.fill(gps, msgCode, gpsStatus, lon, lat, speed, direction, obt);
        return gps;
    }

    @Override
    public double getPowerMileage() {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public byte[] getBatteryVolElectric() {
        return ByteUtils.shortToByte((short) (((ByteUtils.getInt(data, 72, 74) / 10) + 1000) * 10));
    }

    @Override
    public int getTemperatureImbalanceAlarm() {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public int getOverTemperatureRangeAlarm() {
        AlarmInfo alarmInfo = getBatSysFaultCodes();
        if (alarmInfo.getValue().indexOf("一级故障 电池温差过大") != -1 || alarmInfo.getValue().indexOf("电池温差过大") != -1) {
            return 1;
        }
        return 0;
    }

    @Override
    public int getBatteryPoleOverTempAlarm() {
        AlarmInfo alarmInfo = getBatSysFaultCodes();
        if (alarmInfo.getValue().indexOf("一级故障 极柱温度过高") != -1 || alarmInfo.getValue().indexOf("极柱温度过高") != -1) {
            return 1;
        }
        return 0;
    }

    @Override
    public int getOverTemperatureAlarm() {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public int getBatSOCLowAlarm() {
        return 0;
    }

    @Override
    public int getBatSOCTooLowAlarm() {
        return 0;
    }

    @Override
    public int getBatSocHighAlarm() {
        return 0;
    }

    @Override
    public int getSingleOverVolAlarm() {
        AlarmInfo alarmInfo = getBatSysFaultCodes();
        if (alarmInfo.getValue().indexOf("单体电压过高") != -1) {
            return 1;
        }
        return 0;
    }

    @Override
    public int getSingleUnderVolFault() {
        AlarmInfo alarmInfo = getBatSysFaultCodes();
        if (alarmInfo.getValue().indexOf("单体电压过低") != -1) {
            return 1;
        }
        return 0;
    }

    @Override
    public int getInsulatedAlarm() {
        AlarmInfo alarmInfo = getBatSysFaultCodes();
        if (alarmInfo.getValue().indexOf("一级故障 绝缘故障") != -1 || alarmInfo.getValue().indexOf("绝缘故障") != -1) {
            return 1;
        }
        return 0;
    }

    @Override
    public int batPackOverVolAlarm() {
        AlarmInfo alarmInfo = getBatSysFaultCodes();
        if (alarmInfo.getValue().indexOf("一级故障 总电压过高") != -1 || alarmInfo.getValue().indexOf("总电压过高") != -1) {
            return 1;
        }
        return 0;
    }

    @Override
    public int batPackUnderVolAlarm() {
        AlarmInfo alarmInfo = getBatSysFaultCodes();
        if (alarmInfo.getValue().indexOf("一级故障 总电压过低") != -1 || alarmInfo.getValue().indexOf("总电压过低") != -1) {
            return 1;
        }
        return 0;
    }

    @Override
    public int batPackNotMatchAlarm() {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public int batDifferenceAlarm() {
        // TODO Auto-generated method stub
        return 0;
    }
}